package com.iflytek.jobs.service.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.iflytek.jobs.service.domain.JobInfo;
import com.iflytek.jobs.service.domain.vo.JobInfoExcel;
import com.iflytek.jobs.service.mapper.JobInfoMapper;
import com.iflytek.jobs.service.service.IJobInfoService;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 岗位信息Service业务层处理
 * 
 * @author chenhs
 * @date 2023-02-03
 */
@Service
public class JobInfoServiceImpl implements IJobInfoService
{
    @Autowired
    private JobInfoMapper jobInfoMapper;

    /**
     * 查询岗位信息
     * 
     * @param jobId 岗位信息主键
     * @return 岗位信息
     */
    @Override
    public JobInfo selectJobInfoByJobId(String jobId)
    {
        return jobInfoMapper.selectJobInfoByJobId(jobId);
    }

    /**
     * 查询岗位信息列表
     * 
     * @param jobInfo 岗位信息
     * @return 岗位信息
     */
    @Override
    public List<JobInfo> selectJobInfoList(JobInfo jobInfo)
    {
        return jobInfoMapper.selectJobInfoList(jobInfo);
    }

    /**
     * 新增岗位信息
     * 
     * @param jobInfo 岗位信息
     * @return 结果
     */
    @Override
    public int insertJobInfo(JobInfo jobInfo)
    {
        jobInfo.setCreateTime(DateUtils.getNowDate());
        return jobInfoMapper.insertJobInfo(jobInfo);
    }

    /**
     * 修改岗位信息
     * 
     * @param jobInfo 岗位信息
     * @return 结果
     */
    @Override
    public int updateJobInfo(JobInfo jobInfo)
    {
        jobInfo.setUpdateTime(DateUtils.getNowDate());
        return jobInfoMapper.updateJobInfo(jobInfo);
    }

    /**
     * 批量删除岗位信息
     * 
     * @param jobIds 需要删除的岗位信息主键
     * @return 结果
     */
    @Override
    public int deleteJobInfoByJobIds(String[] jobIds)
    {
        return jobInfoMapper.deleteJobInfoByJobIds(jobIds);
    }

    /**
     * 删除岗位信息信息
     * 
     * @param jobId 岗位信息主键
     * @return 结果
     */
    @Override
    public int deleteJobInfoByJobId(String jobId)
    {
        return jobInfoMapper.deleteJobInfoByJobId(jobId);
    }
    
    @Override
    public void importData(List<JobInfoExcel> jobList) {
    	jobList.forEach(jobExcel->{
    		//插入企业信息
//    		ComInfo comInfo = new ComInfo();
//    		comInfo.setComName(jobExcel.getComName());
//    		comInfo.setComType(this.comTypeConvert(jobExcel));
//    		comInfoService.insertComInfo(comInfo);
    		//插入岗位信息
    		JobInfo jobInfo = BeanUtil.copyProperties(jobExcel, JobInfo.class, "jobDegree","trainee");
    		jobInfo.setJobDegree(this.JobDegreeConvert(jobExcel));
    		jobInfo.setTrainee(this.traineeConvert(jobExcel));
    		this.insertJobInfo(jobInfo);
    	});
    	
    }
    
    public String JobDegreeConvert(JobInfoExcel jobExcel) {
    	String jobDegree = jobExcel.getJobDegree();
    	if(jobDegree.contains("大专") || jobDegree.contains("专科")) {
    		return "1";
    	}else{
    		return "2";
    	}
    }
    
    public String traineeConvert(JobInfoExcel jobExcel) {
    	String trainee = jobExcel.getTrainee();
    	if(trainee.contains("实习生") && trainee.contains("应届生")) {
    		return "3";
    	}else if(trainee.contains("实习生")) {
    		return "1";
    	}else if(trainee.contains("应届生")) {
    		return "2";
    	}else {
    		return "4";
    	}
    }
    
    public int comTypeConvert(JobInfoExcel jobExcel) {
    	String comType = jobExcel.getComType();
    	if(comType.contains("Ⅰ")) {
    		return 1;
    	}else if(comType.contains("Ⅱ")) {
    		return 2;
    	}else if(comType.contains("Ⅲ")) {
    		return 3;
    	}else {
    		return 4;
    	}
    }
}
